package cn.zongtilei;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.isever.IStudentService;
import cn.lei.Student;
import cn.severimpl.StudentServiceImpl;

public class AddStudentServlet extends HttpServlet {
	private IStudentService studentservice = new StudentServiceImpl();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 1.等到浏览器传递过来的参数信息
		String name = req.getParameter("name");
		Integer age = Integer.parseInt(req.getParameter("age"));
		String gender = req.getParameter("gender");
		Student student = new Student(name, age, gender);
		// 2.调用service处理
		boolean result = studentservice.insert(student);
		System.out.println(result ? "成功" : "失败");
		// 3.转发或者重定向到列表界面
		resp.sendRedirect("/Java1807Web/findStudent"); // 充定向 这也是告诉浏览器让它再发一个请求
	}
}
